<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>滚动到最顶部</title>
		<style>
			* {
				padding: 0;
				margin: 0;
			}

			#top {
				width: 100px;
				height: 100px;
				border-radius: 50%;
				background-color: yellow;
				text-align: center;
				line-height: 100px;
				position: fixed;
				right: 50px;
				bottom: 50px;
				/* 透明度 */
				opacity: 0;
				transition: .5s;
			}

		</style>
	</head>
	<body>
		呵呵
		<div id="top">
			顶部
		</div>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		哈哈

	</body>
</html>
<script>
	
	var topDiv = document.getElementById('top');
	window.onscroll = function() {
		// console.log(111);
		console.log(document.documentElement.scrollTop);

		if (document.documentElement.scrollTop >= 250) {
			topDiv.style.opacity = 1;
			topDiv.onclick = scroll;
		} else {
			topDiv.style.opacity = 0;
			topDiv.onclick = null;
		}
	};


	function scroll() {
		// document.documentElement.scrollTop = 0;
		var n = document.documentElement.scrollTop / 10;
		var timer = setInterval(function() {
			if (document.documentElement.scrollTop <= 0) clearInterval(timer);
			document.documentElement.scrollTop -= n;
			console.log(666);
		}, 16);
	};




</script>


